package com.mh.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import cn.hutool.core.codec.Morse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import oshi.hardware.common.AbstractSensors;

/**
 * Date:2023/9/11
 * author:zmh
 * description: 图形验证码
 **/

@RestController
@CrossOrigin
@RequestMapping("common")
@Slf4j
public class CaptchaController {

    @GetMapping("/captcha")
    public String getCaptcha(){
        // 定义图形验证码的长和宽
        CircleCaptcha circleCaptcha = CaptchaUtil.createCircleCaptcha(200, 100,4, 10);
        // 将验证码图片转为base64编码后返回
        String imageBase64 = circleCaptcha.getImageBase64();
        // 获取验证码字符串
        String code = circleCaptcha.getCode();
        log.info("code:{}", code);
        log.info("imageBase64:{}", "data:image/png;base64," + imageBase64);

        // 莫斯电码
        Morse morse = new Morse('.','-',' ');
        log.info("morse:{}", morse.encode(code));
        // 系统CPU温度

        return imageBase64;
    }


}




















